package com.huizu.common.core.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

/**
 * spring redis 工具类
 *  实现排序
 * @author ruoyi
 **/
@Component
public class RedisRank {

    @Autowired
    public RedisTemplate redisTemplate;

    public void addBatchUserCj(String xyId,String key,Double value){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();
        zSetOperations.add(xyId+"userCj",key,value);


    }

    public Long getRankUserCj(String xyId,String key){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();
        return zSetOperations.reverseRank(xyId+"userCj",key);
    }

    public void removeRankUserCj(String xyId){
       redisTemplate.delete(xyId+"userCj");

    }

    public void addBatchLdCj(String xyId,String key,Double value){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();

        zSetOperations.add(xyId+"ldCj",key,value);
    }


    public Long getRankLdCj(String xyId,String key){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();

        return zSetOperations.reverseRank(xyId+"ldCj",key);
    }

    public void removeRankLdCj(String xyId){

        redisTemplate.delete(xyId+"ldCj");
    }

    public void addBatchLlCj(String xyId,String key,Double value){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();
            zSetOperations.add(xyId+"llCj",key,value);
        }


    public Long getRankLlCj(String xyId,String key){
        ZSetOperations zSetOperations = redisTemplate.opsForZSet();
        return zSetOperations.reverseRank(xyId+"llCj",key);
    }

    public void removeRankLlCj(String xyId){
        redisTemplate.delete(xyId+"llCj");
    }


}
